using System.Collections.Generic;
using System.Linq;
using Slf;
using Slf.Config;
using Slf.Resolvers;
using System.Reflection;

namespace SLF.Test.Resolver
{
  /// <summary>
  /// Extends the class which is the target of this test to modify its
  /// constructor behaviour so that configuration is not immediately loaded
  /// as the class is constructed, and also to expose 
  /// private data
  /// </summary>
  public class AppConfigFactoryResolverTarget : AppConfigFactoryResolver
  {
    public override void Load()
    {
      // do not call the base class implementation
      // base.Load();
    }

    /// <summary>
    /// Expose the test logger
    /// </summary>
    public TestLogger TestLogger
    {
      get
      {
        return DiagnosticLogger as TestLogger;
      }
    }

    public List<NamedFactory> GetFactories()
    {
      FieldInfo fi = typeof(NamedFactoryResolver).GetField("_factoryCache",
        BindingFlags.NonPublic | BindingFlags.Instance);
      return fi.GetValue(this)!=null ? (List<NamedFactory>) fi.GetValue(this) : null;
    }


    public new void LoadConfiguration(SlfConfigurationSection config)
    {
      base.LoadConfiguration(config);
    }
  }
}